<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>客户退货单据查询</title>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.5.5.4/themes/metro/easyui.css"></link>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.5.5.4/themes/icon.css"></link>
    <script type="text/javascript" src="/static/jquery-easyui-1.5.5.4/jquery.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.5.5.4/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.5.5.4/locale/easyui-lang-zh_CN.js"></script>

    <script type="text/javascript" src="/static/js/date.js"></script>
    <script type="text/javascript">


        function formatUser(val, row) {
            return val.trueName + "&nbsp;(" + val.userName + ")&nbsp;";
        }


        function searchCustomerReturn() {
            $("#dg2").datagrid("loadData", {total: 0, rows: []});
            var customerId;
            if (isNaN($("#s_customer").combobox("getValue"))) {
                customerId = "";
            } else {
                customerId = $("#s_customer").combobox("getValue");
            }
            $("#dg").datagrid({
                url: '/admin/customerReturnList/list',
                queryParams: {
                    customerReturnNumber: $("#s_customerReturnNumber").val(),
                    "customer.id": customerId,
                    state: $("#s_state").combobox("getValue"),
                    bCustomerReturnDate: $("#s_bCustomerReturnDate").datebox("getValue"),
                    eCustomerReturnDate: $("#s_eCustomerReturnDate").datebox("getValue")
                }
            });
        }

        function formatSupplier(val, row) {
            return val.name;
        }

        function formatAmountPayable(val, row) {
            return "€" + val;
        }

        function formatUser(val, row) {
            return val.trueName;
        }

        function deleteCustomerReturn() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length != 1) {
                $.messager.alert("系统提示", "请选择一条要删除的客户退货单！");
                return;
            }
            var id = selectedRows[0].id;
            $.messager.confirm("系统提示", "<font color=red>删除客户退货单后将无法恢复，是否删除?</font>", function (r) {
                if (r) {
                    $.post("/admin/customerReturnList/delete", {id: id}, function (result) {
                        if (result.success) {
                            $("#dg").datagrid("reload");
                            $("#dg2").datagrid("reload");
                        } else {
                            $.messager.alert("系统提示", result.errorInfo);
                        }
                    }, "json");
                }
            });
        }


        $(document).ready(function () {

            $("#s_bCustomerReturnDate").datebox("setValue", genLastMonthDayStr()); // 设置上个月日期
            $("#s_eCustomerReturnDate").datebox("setValue", genTodayStr()); // 设置当前日期

            $("#dg").datagrid({
                onClickRow: function (index, row) {
                    $("#dg2").datagrid({
                        url: '/admin/customerReturnList/listGoods',
                        queryParams: {
                            customerReturnListId: row.id
                        }
                    });
                }
            });

        });


        function formatPrice(val, row) {
            return "€" + val;
        }

        function formatTotal(val, row) {
            return "€" + val;
        }
    </script>
</head>
<body class="easyui-layout" style="margin: 1px">
<div region="north" style="height: 350px">
    <table id="dg" title="客户退货单据查询" class="easyui-datagrid"
           fitColumns="true" rownumbers="true" singleSelect="true"
           fit="true" toolbar="#tb">
        <thead>
        <th field="id" width="20" align="center" hidden="true">客户退货单ID</th>
        <th field="customerReturnNumber" width="30" align="center">客户退货单号</th>
        <th field="customerReturnDate" width="20" align="center">客户退货日期</th>
        <th field="customer" width="50" align="center" formatter="formatSupplier">客户</th>
        <th field="amountPayable" width="20" align="right" formatter="formatAmountPayable">客户退货金额</th>
        <th field="user" width="20" align="center" formatter="formatUser">操作员</th>
        <th field="remarks" width="100" align="center">备注</th>
        </thead>
    </table>

    <div id="tb">
        <fieldset style="border-color: #E7F0FF">
            <legend>查询设置</legend>
            &nbsp;单据号&nbsp;
            <input type="text" id="s_customerReturnNumber" size="15"
                   onkeydown="if(event.keyCode==13) searchCustomerReturn()"/>
            &nbsp;&nbsp;&nbsp;客户：&nbsp;<input class="easyui-combobox" id="s_customer" name="customer.id"
                                              style="width: 200px" required="true"
                                              data-options="required:true,panelHeight:'auto',valueField:'id',textField:'name',url:'/admin/customer/comboList'"/>
            &nbsp;&nbsp;&nbsp;是否付款&nbsp;
            <select class="easyui-combobox" id="s_state" style="width: 100px" editable="false" panelHeight="auto">
                <option value="">全部</option>
                <option value="1">已付</option>
                <option value="2">未付</option>
            </select>
            &nbsp;&nbsp;&nbsp;日期：&nbsp;
            <input id="s_bCustomerReturnDate" class="easyui-datebox" editable=false style="width:100px"/>
            &nbsp;&nbsp;-&nbsp;&nbsp;
            <input id="s_eCustomerReturnDate" class="easyui-datebox" editable=false style="width:100px"/>
            &nbsp;&nbsp;<a href="javascript:searchCustomerReturn()" class="easyui-linkbutton" iconCls="icon-search"
                           plain="true">搜索</a>
            &nbsp;&nbsp;<a href="javascript:deleteCustomerReturn()" class="easyui-linkbutton" iconCls="icon-remove"
                           plain="true">删除</a>
        </fieldset>
    </div>
</div>
<div region="center" style="margin-top: 5px">
    <table id="dg2" class="easyui-datagrid"
           fitColumns="true" rownumbers="true" singleSelect="true"
           fit="true">
        <thead>
        <th field="code" width="30" align="center">商品编码</th>
        <th field="name" width="150" align="center">商品名称</th>
        <th field="model" width="50" align="center">商品型号</th>
        <th field="price" width="50" align="right" formatter="formatPrice">单价</th>
        <th field="num" width="50" align="center">数量</th>
        <th field="unit" width="50" align="center">单位</th>
        <th field="total" width="50" align="right" formatter="formatTotal">总金额</th>
        </thead>
    </table>

</div>

</body>
</html>